package drds.common.db.xml_mapping.script.xml_tags;


public class If implements DynamicNode {
  private final ExpressionEvaluator evaluator;
  private final String test;
  private final DynamicNode contents;

  public If(DynamicNode contents, String test) {
    this.test = test;
    this.contents = contents;
    this.evaluator = new ExpressionEvaluator();
  }

  @Override
  public boolean apply(DynamicNodeContext dynamicNodeContext) {
    if (evaluator.evaluateBoolean(test, dynamicNodeContext.getBindings())) {
      contents.apply(dynamicNodeContext);
      return true;
    }
    return false;
  }

}
